<div class="form_container">
    {% if TheUser %}<h1>Edit Profile</h1>
    {% else %}<h1>Create Profile</h1>
    {% endif %}
<form action='.' enctype="multipart/form-data" method='post'>{% csrf_token %}
    <button type="submit" class="button SaveButton" name="Save" value="SaveEdit" style="position: fixed; bottom: 0px; right: 0px; z-index: 5;" title="Save and Continue Editing"><a>Save</a></button>

<table>
        {% if TheUser %}
        <tr>
            {% load files %}
            {% get_file_list for TheUser.user as Files %}
                <th>Avatar:</th>
            <td>
            {% if Files.avatar %}
                <img src="{{Files.avatar.url}}">
            {% endif %}
            {% get_file_form for TheUser.user as file_form %}
            {% get_file_form_target as file_data %}
                {% for field in file_form.hidden_fields %}
                    <div>{{ field }}</div>
                {% endfor %}
                <div><input type="hidden" name="id_file_title" id="id_file_title" value="avatar" /></div>
                <div><input type="hidden" name="id_file_description" id="id_file_description" value="" /></div>
                {% if file_form.file.errors %}{{ file_form.file.errors }}{% endif %}
                <p {% if file_form.file.errors %} class="error"{% endif %}>{{file_form.file}}</p>
                {% if file_form.honeypot.errors %}{{ file_form.honeypot.errors }}{% endif %}
                <p style="display:none;" {% if file_form.honeypot.errors %} class="error"{% endif %}>{{file_form.honeypot.label_tag}} {{file_form.honeypot}}</p>
            </td>
        </tr>
        {% endif %}
{{user_form.as_table}}
{{course_form.as_table}}
{% for additions,form in addition_forms %}
    {{form.as_table}}
{% endfor %}
<tr>
    <td colspan="4" class="Buttons">
        <button type="submit" class="button SaveButton floatleft" name="Save" value="SaveEdit" title="Save and Continue Editing">Save and Continue</button>
        <button type="submit" class="button SaveButton floatleft" name="Save" value="SaveReturn" title="Save and Return to User Management">Save and Return</button>
        <a class="button SaveButton" href="{% course_url management app='users' %}">Cancel</a>
    </td>
</tr>
<table>
</form>
{% if not TheUser and OtherUsers%}
<hr>
    <h1>Add Existing Users</h1>
    <table border="0">
    <tr><th class="border-bottom" colspan="2"><a name="#add_user_list"></a>User</th><th class="border-bottom">Username</th><th class="border-bottom">Email</th><th colspan="100%" class="border-bottom">Options</th></tr>
    {% for user in OtherUsers %}
        <tr>
            {% get_file_list for user as Files %}
            <td><img src="{% if Files.avatar %}{{Files.avatar.url}}{% else %}{{STATIC_URL}}images/BlankAvatar.png{% endif %}" height="75"></td>
            <th>{{user.last_name}}, {{user.first_name}}</th>
            <td>{{user.username}}</td>
            <td>{{user.email}}</td>
            <td class="management_option"><a class="button smallbutton" href="{% course_url management app='users' command='add' arguments=user.username %}" title="Add this user to the course as astudent (can be changed in User management)">Add</a></td>
        </tr>
    {% endfor %}
</table>
{% endif %}
</div>
